package com.tianyuan.lims.dms.common;

import com.jfinal.config.Routes;
import com.jfinal.core.Controller;
import org.reflections.Reflections;

import java.util.Set;

public class DmsRouter extends Routes {
    @Override
    public void config() {
//        addInterceptor(new DmsInterceptor());
//        add("/device", DeviceController.class);
//        add("/employee", EmployeeController.class);
//        add("/detectTask", TaskController.class);
//        add("/ProvinceLaboratory", ProvinceLaboratoryController.class);
//        add("/City", CityController.class);
//        add("/monitoringAgency", MonitoringAgencyController.class);
//        add("/app", AppController.class);
//        add("/station", StationController.class);
//        add("/organization", OrganizationController.class);
//        add("/report", ReportController.class);
//        add("/expert", ExpertController.class);
        // 扫描并添加控制器
        scanControllerInPkg("com.tianyuan.lims.dms.controller"); // 替换为你的控制器包名
    }

    // 扫描指定包及其所有子包下的所有控制器类，并添加到路由中
    private void scanControllerInPkg(String pkgName) {
        Reflections reflections = new Reflections(pkgName);
        Set<Class<? extends Controller>> controllerClasses = reflections.getSubTypesOf(Controller.class);
        for (Class<? extends Controller> controllerClass : controllerClasses) {
            if(controllerClass.getPackage().getName().contains(pkgName)){
                String controllerName = controllerClass.getSimpleName().replaceFirst("Controller$", "");

                char firstChar = Character.toLowerCase(controllerName.charAt(0));
                String remainingChars = controllerName.substring(1);
                String result = firstChar + remainingChars;
                //System.out.println("add controller: /" + result);
                add("/" + result, controllerClass);
            }
        }
    }




}
